package annotool.select;

import java.util.ArrayList;
import java.util.Vector;

import mpicbg.imagefeatures.Feature;

public class ConsensusFeatures 
{
	Vector<Feature> matchedFeatures = new Vector<Feature>();
	ArrayList<Float> mScore = new ArrayList<Float>();
	ArrayList<Integer> fPosition1 = new ArrayList<Integer>();
	ArrayList<Integer> fPosition2 = new ArrayList<Integer>();
	int length;
	
	//constructor
	public ConsensusFeatures(Vector<Feature> matchedFeaures, ArrayList<Float> mScore, ArrayList<Integer> fPosition1, ArrayList<Integer> fPosition2, int length)
	{
		this.matchedFeatures = matchedFeaures;
		this.mScore = mScore;
		this.fPosition1 = fPosition1;
		this.fPosition2 = fPosition2;
		this.length = length;
	}

	public Vector<ClassFeatures> removeImageDuplicates() 
	{
		Vector<ClassFeatures> cf = new Vector<ClassFeatures>();
		ArrayList<Integer> positionClone = new ArrayList<Integer>(fPosition1);
		for(int i = 0; i < fPosition1.size(); i++)
		{
			int index = fPosition1.get(i);
			if(positionClone.indexOf(index) != -1)
			{
				float totalScore = 0;
				while(positionClone.indexOf(index) != -1)
				{
					totalScore += mScore.get(positionClone.indexOf(index));
					positionClone.remove(positionClone.indexOf(index));
				}
				cf.add(new ClassFeatures(matchedFeatures.get(i), (totalScore / (length - 1)),
						fPosition1.get(i),fPosition2.get(i)));
			}
		}
		return cf;
	}

	public ArrayList<Float> getMScore() 
	{
		return mScore;
	}

	public Vector<Feature> getMatchedFeatures() 
	{
		return matchedFeatures;
	}

	public ArrayList<Integer> getFPosition1() 
	{
		return fPosition1;
	}
	public ArrayList<Integer> getFPosition2() 
	{
		return fPosition2;
	}
	
	
}
